package com.app.mail.dao.impl;

import com.app.mail.dao.MailDao;
import com.app.mail.model.StoreMail;
import com.app.sysmodule.dao.impl.BaseDaoImpl;
import com.app.sysmodule.exception.DBException;

import java.util.Date;
import java.util.List;

/**
 * Created by song on 2018/1/31.
 */
public class MailDaoImpl extends BaseDaoImpl<StoreMail> implements MailDao {
    @Override
    public void updateIsSend(long id, long isSend) throws DBException {
        try {
            String hql = " update StoreMail set isSend=(:isSend) , updateDate=(:updateDate) where id=(:id)  ";
            this.getSession().createQuery(hql).setParameter("isSend", isSend).setParameter("updateDate", new Date()).setParameter("id", id).executeUpdate();
        } catch (Exception e) {
            throw new DBException(e.getMessage());
        }
    }

    @Override
    public List<String> getAllReceiver() throws DBException {
        try{
            String sql = "SELECT email_account from a_store_mail where is_send=0";
            return this.getSession().createSQLQuery(sql).list();
        }catch (Exception e){
            throw new DBException(e.getMessage());
        }
    }
}
